define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'xilujob/salary/index' + location.search,
                    add_url: 'xilujob/salary/add',
                    edit_url: 'xilujob/salary/edit',
                    del_url: 'xilujob/salary/del',
                    //multi_url: 'xilujob/salary/multi',
                    table: 'xilujob_salary',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'option_type', title: __('Option_type'), searchList: {"1":__('Option_type 1'),"2":__('Option_type 2'),"3":__('Option_type 3')}, formatter: Table.api.formatter.normal},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'min', title: __('Min')},
                        {field: 'max', title: __('Max')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                $('form').data('validator-options',{
                    rules: {
                        salary_max: function (value) {
                            return $('#c-max').val()==='' || parseInt($('#c-max').val())>parseInt($('#c-min').val());
                        }
                    }
                });
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});